package threadcoreknowledge.sixstates;

/**
 *  六个线程状态之一： 展示线程的NEW、RUNNABLE、Terminated状态。即使是正在运行，也是Runnable状态，而不是Running。
 * @Author wushaopei
 * @Date 2021/4/18 23:51
 * @Version 1.0
 */
public class NewRunnableTerminated implements Runnable{

    public static void main(String[] args) {
        Thread thread = new Thread(new NewRunnableTerminated());
        // 打印出 NEW 的状态
        System.out.println(thread.getState());
        thread.start();
        // 打印 Runnable 状态
        System.out.println(thread.getState());
        try {
            Thread.sleep(10);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
        // 打印出RUNNABLE的状态，即使是正在运行，也是RUNNABLE,而不是RUNNING
        System.out.println(thread.getState());

        try {
            Thread.sleep(100);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
        // 打印出 TERMINATED状态
        System.out.println(thread.getState());
    }

    @Override
    public void run() {
        for (int i = 0 ; i < 1000; i++){
            System.out.println(i);
        }
    }
}
